package com.tanhua.manage.exception;

import com.tanhua.manage.vo.CommonResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class ExceptionAdvice {


    @ExceptionHandler(value = Exception.class)
    public ResponseEntity handlerException(Exception e){ //key: 服务器异常
        //1. 打印异常
        e.printStackTrace();
        //获取当前的异常的信息
        String message = e.getMessage();
        CommonResponse commonResponse = new CommonResponse(message);
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(commonResponse);


    }
}
